package com.thiswhyme.gatewayserver.controller;

import com.alibaba.fastjson.JSON;
import com.thiswhyme.common.response.ResponseVo;
import com.thiswhyme.gatewayserver.dto.Constants;
import com.thiswhyme.gatewayserver.dto.UserDto;
import com.thiswhyme.gatewayserver.utils.JwtHelper;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author thiswhyme 2020/6/1
 */
@RestController
@RequestMapping("/auth")
public class AuthController {

    @PostMapping("/login")
    public ResponseVo<UserDto> login() {
        UserDto userDto = new UserDto().setUserId(123456L).setUsername("TestUser");
        userDto.setToken(JwtHelper.createJWT(userDto.getUserId().toString()
                , JSON.toJSONString(userDto)
                , Constants.JWT_TTL));
        return ResponseVo.success(userDto);
    }
}
